package com.cloud.form.api.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Lang;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.cloud.form.api.entity.FormFieldAuth;
import com.cloud.form.common.driver.SimpleInlangDriver;
import com.cloud.form.common.utils.BaseMapperHelper;

public interface FormFieldAuthMapper extends BaseMapperHelper<FormFieldAuth> {

	@Select("select a.field_id, a.auth_code from form_field_auth a where a.part_id = #{partId} and a.act_def_id = #{actDefId}")
	@Results({ @Result(property = "fieldId", column = "field_id", javaType = Long.class),
			@Result(property = "authCode", column = "auth_code", javaType = Integer.class) })
	List<FormFieldAuth> listFieldByFormPart(@Param("actDefId") long actDefId, @Param("partId") long partId);

	@Delete("delete from form_field_auth where form_id not in (select form_id from form_input_auth)")
	void deleteActFormField();
	

	@Select("select a.field_id, a.auth_code from form_field_auth a where a.form_id = #{formId} and a.part_id in (#{parts}) and a.act_def_id = #{actDefId}")
	@Lang(SimpleInlangDriver.class)
	@Results({ @Result(property = "fieldId", column = "field_id", javaType = Long.class),
		@Result(property = "authCode", column = "auth_code", javaType = Integer.class) })
	List<FormFieldAuth> listFieldByFormActParts(@Param("formId")long formId, @Param("actDefId")long actDefId, @Param("parts")List<Long> parts);
}